package com.ztk.threadbasic.join;

public class ThreadJoin {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            System.out.println("thread1 is running");
            try {
                Thread.sleep(5 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("thread1 is endding");
        });

        Thread thread2 = new Thread(() -> {
            System.out.println("thread2 is running");
            try {
                thread1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("thread2 is endding");
        });

        thread1.start();
        Thread.sleep(2 * 1000);
        thread2.start();
    }
}
